package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: CategoryController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 分类管理
 * @Author 孤妤
 * @Date: 2023/12/7 10:11
 */
@Tag(name = "分类管理")
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/findByParentId/{id}")
    @Operation(summary = "根据id获取分类列表节点")
    public Result<List<Category>> findByParentId(@PathVariable Long id){
        List<Category> categoryList = categoryService.findByParentId(id);
        return Result.build(categoryList, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/exportData")
    @Operation(summary = "数据导出为Excel文件")
    public void exportData(HttpServletResponse response) {
        categoryService.exportData(response);
    }
    @PostMapping("importData")
    @Operation(summary = "Excel文件导入为数据")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
